package nuc.url;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class UrlThread implements Runnable{

    @Override
    public void run() {
        //创建url对象
        try {
            URL url = new URL("https://ai.taobao.com/");
            //调用url对象的openConnection方法，获得URLConnection
            URLConnection conn = url.openConnection();
            //调用URLConnection方法的getInputStream
            InputStream in = conn.getInputStream();
            //I/O操作
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(in));
            String line =null;
            while ((line=br.readLine()) != null){
                System.out.println(line);
            }
            br.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
